﻿using System;
using System.Text;

namespace dotHTML.HTML {
    /// <summary>
    /// Represents a key generator.
    /// </summary>
    [Serializable]
    [Standalone]
    public class Keygen : Element {
        /// <summary>
        /// Represents the possible choices for key type.
        /// </summary>
        public enum KeyTypeChoices {
            /// <summary>
            /// Use the RSA algorithm.
            /// </summary>
            Rsa,
            /// <summary>
            /// Use the DSA algorithm.
            /// </summary>
            Dsa,
            /// <summary>
            /// Use the EC algorithm.
            /// </summary>
            EC
        }
        private bool _autofocus;
        private string _challenge;
        private bool _disabled;
        private Form _form;
        private KeyTypeChoices? _keytype;
        private string _name;

        /// <summary>
        /// Determines whether or not this control has focus when the page is
        /// loaded.
        /// </summary>
        public bool AutoFocus {
            get { return _autofocus; }
            set { _autofocus = value; }
        }

        /// <summary>
        /// Determines the challenge string to be used with this key generator.
        /// </summary>
        public string Challenge {
            get { return _challenge; }
            set { _challenge = value; }
        }

        /// <summary>
        /// Determines whether or not this control is disabled by default.
        /// </summary>
        public bool Disabled {
            get { return _disabled; }
            set { _disabled = value; }
        }

        /// <summary>
        /// Determines the parent form of this control.
        /// </summary>
        public Form Form {
            get { return _form; }
            set { _form = value; }
        }

        /// <summary>
        /// Determines the cipher type that this key generator uses.
        /// </summary>
        public KeyTypeChoices? KeyType {
            get { return _keytype; }
            set { _keytype = value; }
        }

        /// <summary>
        /// Determines the name of this key generator.
        /// </summary>
        public string Name {
            get { return _name; }
            set { _name = value; }
        }

        /// <summary>
        /// Gets a formatted string of all local attributes of this element
        /// (not including the base attributes).
        /// </summary>
        /// <param name="sb">The StringBuilder to write this element's
        /// attribute data to.</param>
        protected override void WriteLocalAttributes(StringBuilder sb) {
            AttributeWriter.Write(sb, _autofocus, "autofocus");
            AttributeWriter.Write(sb, _challenge, "challenge");
            AttributeWriter.Write(sb, _disabled, "disabled");
            if (_form != null) {
                AttributeWriter.Write(sb, _form.ID, "form");
            }
            AttributeWriter.Write(sb, _keytype, "keytype", true);
            AttributeWriter.Write(sb, _name, "name");

        }
    }
}
